package com.scqkxx.gamebox.activity.space;

import android.support.v7.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVObject;
import com.avos.avoscloud.AVQuery;
import com.avos.avoscloud.FindCallback;
import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.activity.game.adapter.GameAdapter;
import com.scqkxx.gamebox.activity.game.presenter.GamePresenter;
import com.scqkxx.gamebox.activity.space.adapter.RecyleAdapter;
import com.scqkxx.gamebox.databinding.ActivityRecycleBinding;
import com.scqkzqtz.base.base.BaseActivity;

import java.util.ArrayList;
import java.util.List;

public class RecycleActivity extends BaseActivity<ActivityRecycleBinding> {
    private List<AVObject> mGameListData;
    private RecyleAdapter mGameAdapter;

    @Override
    public int setLayoutId() {
        return R.layout.activity_recycle;
    }

    @Override
    public void init() {
        binding.mTitleView.setOnTitleClickListener((int titleType) -> finish());
        initView();
        initData();
    }

    private void initView() {
        mGameListData = new ArrayList<>();
        mGameAdapter = new RecyleAdapter(R.layout.game_item_layout, mGameListData);
        View view2 = inflate(com.scqkzqtz.base.R.layout.layout_empty);
        mGameAdapter.setEmptyView(view2);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        binding.mRecyclerView.setLayoutManager(linearLayoutManager);
        binding.mRecyclerView.setAdapter(mGameAdapter);
    }

    //请求数据监听
    private void initData() {
        AVQuery<AVObject> query = AVQuery.getQuery("Goods");
        query.whereEqualTo("isDisable", 1);
        query.findInBackground(new FindCallback<AVObject>() {
            @Override
            public void done(List<AVObject> avObjects, AVException avException) {
                if (avException == null) {
                    if (avObjects.size() > 0){
                        mGameListData.clear();
                        mGameListData.addAll(avObjects);
                        mGameAdapter.setNewData(mGameListData);
                    }
                }else {
                    Log.e("TAG" , avException.getMessage());
                }
            }
        });
    }
}
